package org.springblade.demo2.controller;

import com.alibaba.druid.stat.TableStat;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.demo2.entity.Blog;
import org.springblade.demo2.service.BlogService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api")
@AllArgsConstructor
public class Demo2Controller {

	private BlogService blogService;

	@PostMapping("/save")
	public R save(@RequestBody  Blog blog){
		return R.status(blogService.save(blog));
	}

	@PostMapping("/remove")
	public R remove(@RequestParam Integer id){
		return R.status(blogService.removeById(id));
	}

	@PostMapping("/update")
	public R update(@RequestBody  Blog blog){
		return R.status(blogService.updateById(blog));
	}

	@ApiLog("Blog详情")
	@GetMapping("/detail")
	@ApiOperation(value = "查看详情",notes = "传入主键")
	public R<Blog> detail(@RequestParam Integer id){
		return R.data(blogService.getById(id));
	}

	//多条模糊查询
	@GetMapping("/list")
	public R<List<Blog>> list(@RequestParam  Map<String,Object> blog){
		return R.data(blogService.list(Condition.getQueryWrapper(blog,Blog.class)));
	}

	//模糊加分页
	@GetMapping("/page")
	public R<IPage<Blog>> page(@RequestParam Map<String,Object> blog, Query query){
		IPage<Blog> page = blogService.page(Condition.getPage(query), Condition.getQueryWrapper(blog, Blog.class));
		return R.data(page);
	}




	@GetMapping("/info")
	public String info(String name){
		return  "my name is:"+name;
	}




}
